﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using ThePingMasterConfiguration.Services;
using ThePingMasterConfiguration.ViewModels;

namespace ThePingMasterConfiguration.Commands
{
    public class AddAddressCommand : ICommand
    {
        private readonly ConfigurationModel _model;
        private readonly IEnterAddressService _enterAddressService;

        public AddAddressCommand(ConfigurationModel model, IEnterAddressService enterAddressService)
        {
            if (model == null) throw new ArgumentNullException("model");
            if (enterAddressService == null) throw new ArgumentNullException("enterAddressService");
            _model = model;
            _enterAddressService = enterAddressService;
        }

        public void Execute(object parameter)
        {
            string newAddress = _enterAddressService.GetAddress();
            if (!String.IsNullOrWhiteSpace(newAddress))
                _model.AddAddress(newAddress);
        }

        public bool CanExecute(object parameter)
        {
            return true;
        }

        public event EventHandler CanExecuteChanged;
    }
}
